<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SplitPath</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>SplitPath</h1>

<p>Separates a file name or URL into its name, directory, extension, and drive.</p>

<pre class="Syntax">SplitPath, InputVar [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive]</pre>
<h3>Parameters</h3>
<dl>

  <dt>InputVar</dt>
  <dd>
    <p>Name of the variable containing the file name to be analyzed.</p>
    <p><span class="ver">[v1.1.21+]:</span> This parameter can be an <code>% <a href="../Variables.htm#Expressions">expression</a></code>, but the percent-space prefix must be used.</p>
  </dd>

  <dt>OutFileName</dt>
  <dd><p>Name of the variable in which to store the file name without its path. The file's extension is included.</p></dd>

  <dt>OutDir</dt>
  <dd><p>Name of the variable in which to store the directory of the file, including drive letter or share name (if present). The final backslash is not included even if the file is located in a drive's root directory.</p></dd>

  <dt>OutExtension</dt>
  <dd><p>Name of the variable in which to store the file's extension (e.g. TXT, DOC, or EXE). The dot is not included.</p></dd>

  <dt>OutNameNoExt</dt>
  <dd><p>Name of the variable in which to store the file name without its path, dot and extension.</p></dd>

  <dt>OutDrive</dt>
  <dd><p>Name of the variable in which to store the drive letter or server name of the file. If the file is on a local or mapped drive, the variable will be set to the drive letter followed by a colon (no backslash). If the file is on a network path (UNC), the variable will be set to the share name, e.g. \\Workstation01</p></dd>

</dl>

<h3>Remarks</h3>
<p>Any of the output variables may be omitted if the corresponding information is not needed.</p>
<p>If <em>InputVar</em> contains a filename that lacks a drive letter (that is, it has no path or merely a relative path), <em>OutDrive</em> will be made blank but all the other output variables will be set correctly. Similarly, if there is no path present, <em>OutDir</em> will be made blank; and if there is a path but no file name present, <em>OutFileName</em> and <em>OutNameNoExt</em> will be made blank.</p>
<p>Actual files and directories in the file system are not checked by this command. It simply analyzes the string given in <em>InputVar</em>.</p>
<p>Wildcards (* and ?) and other  characters illegal in filenames are  treated the same as legal characters, with the exception of colon, backslash, and period (dot), which are processed according to their nature in delimiting the drive letter, directory, and extension of the file.</p>
<p><strong>Support for URLs</strong>: If <em>InputVar</em> contains a colon-double-slash, such as http://domain.com or ftp://domain.com, <em>OutDir</em> is set to the protocol prefix + domain name + directory (e.g. http://domain.com/images) and <em>OutDrive</em> is set to the protocol prefix + domain name (e.g. http://domain.com). All other variables are set according to their definitions above.</p>
<h3>Related</h3>
<p><a href="LoopFile.htm#LoopFileExt">A_LoopFileExt</a>, <a href="StringSplit.htm">StringSplit</a>, <a href="StringGetPos.htm">StringGetPos</a>, <a href="StringMid.htm">StringMid</a>, <a href="StringTrimLeft.htm">StringTrimLeft</a>, <a href="StringLeft.htm">StringLeft</a>, <a href="FileSelectFile.htm">FileSelectFile</a>, <a href="FileSelectFolder.htm">FileSelectFolder</a></p>
<h3>Example</h3>
<pre class="NoIndent">FullFileName = C:\My Documents\Address List.txt
   
<em>; To fetch only the bare filename from the above:</em>
SplitPath, FullFileName, name

<em>; To fetch only its directory:</em>
SplitPath, FullFileName,, dir

<em>; To fetch all info:</em>
SplitPath, FullFileName, name, dir, ext, name_no_ext, drive
   
<em>; The above will set the variables as follows:
; name = Address List.txt
; dir = C:\My Documents
; ext = txt
; name_no_ext = Address List
; drive = C:</em></pre>

</body>
</html>
